<template>
  <div v-loading="loading" class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('关键条款') }}</span>
    </div>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="24">
          <el-form-item :label="$t('管理人权利')" prop="adminRights">
            <el-input v-model="form.adminRights" type="textarea" :placeholder="$t('管理人权利')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('管理人义务')" prop="adminDuty">
            <el-input v-model="form.adminDuty" type="textarea" :placeholder="$t('管理人义务')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('投资人权利')" prop="investorRights">
            <el-input v-model="form.investorRights" type="textarea" :placeholder="$t('投资人权利')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('投资人义务')" prop="investorDuty">
            <el-input v-model="form.investorDuty" type="textarea" :placeholder="$t('投资人义务')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('基金费用')" prop="fundFee">
            <el-input v-model="form.fundFee" type="textarea" :placeholder="$t('基金费用')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('基金业绩报酬')" prop="fundBusinessPay">
            <el-input v-model="form.fundBusinessPay" type="textarea" :placeholder="$t('基金业绩报酬')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('基金设立条件')" prop="fundCondition">
            <el-input v-model="form.fundCondition" type="textarea" :placeholder="$t('基金设立条件')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('关键人士条款')" prop="keyPersonClause">
            <el-input v-model="form.keyPersonClause" type="textarea" :placeholder="$t('关键人士条款')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('投资策略')" prop="investStrategy">
            <el-input v-model="form.investStrategy" type="textarea" :placeholder="$t('投资策略')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('关键交易条款')" prop="keyTransactionTerms">
            <el-input v-model="form.keyTransactionTerms" type="textarea" :placeholder="$t('关键交易条款')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('投资限制')" prop="investLimit">
            <el-input v-model="form.investLimit" type="textarea" :placeholder="$t('投资限制')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('其它说明')" prop="otherExplain">
            <el-input v-model="form.otherExplain" type="textarea" :placeholder="$t('其它说明')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('定向投资区域')" prop="targetInvestArea">
            <el-input v-model="form.targetInvestArea" type="textarea" :placeholder="$t('定向投资区域')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('权益保障方式')" prop="equityEnsureMode">
            <el-input v-model="form.equityEnsureMode" type="textarea" :placeholder="$t('权益保障方式')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('退出方式')" prop="exitMode">
            <el-input v-model="form.exitMode" type="textarea" :placeholder="$t('退出方式')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('基金存续期条款')" prop="fundTerm">
            <el-input v-model="form.fundTerm" type="textarea" :placeholder="$t('基金存续期条款')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('其它特殊条款')" prop="otherCondition">
            <el-input v-model="form.otherCondition" type="textarea" :placeholder="$t('其它特殊条款')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('普通合伙人职责')" prop="generalPartnerDuty">
            <el-input v-model="form.generalPartnerDuty" type="textarea" :placeholder="$t('普通合伙人职责')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('利益冲突解决方案')" prop="gainClashSolution">
            <el-input v-model="form.gainClashSolution" type="textarea" :placeholder="$t('利益冲突解决方案')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('信息披露/知情权条款')" prop="infoDisclosure">
            <el-input v-model="form.infoDisclosure" type="textarea" :placeholder="$t('信息披露/知情权条款')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('基金管理费')" prop="managerAndManagementFee">
            <el-input v-model="form.managerAndManagementFee" type="textarea" :placeholder="$t('基金管理费')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('收益分配方案')" prop="incomeDistributionPlan">
            <el-input v-model="form.incomeDistributionPlan" type="textarea" :placeholder="$t('收益分配方案')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('分配时点')" prop="distributionTimePoint">
            <el-input v-model="form.distributionTimePoint" type="textarea" :placeholder="$t('分配时点')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('优先受益')" prop="distributionOrder">
            <el-input v-model="form.distributionOrder" type="textarea" :placeholder="$t('优先受益')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('非现金分配')" prop="nonCashDistribution">
            <el-input v-model="form.nonCashDistribution" type="textarea" :placeholder="$t('非现金分配')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <!-- 京津冀协同发展 Agricultural modernization with Chinese characteristics -->
        <el-col :span="24">
          <el-form-item :label="$t('产业方向')" prop="industryDirection">
            <el-checkbox-group v-model="form.industryDirection">
              <el-checkbox
                v-for="(dict, index) in industryDirectionOptions"
                :key="index"
                :label="dict.dictValue"
              >{{ $t(dict.dictLabel) }}</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-col>
        <!-- 西藏发展稳定工作 -->
        <el-col :span="24">
          <el-form-item :label="$t('政策分类')" prop="policySort">
            <el-checkbox-group v-model="form.policySort">
              <el-checkbox
                v-for="(dict, index) in policySortOptions"
                :key="index"
                :label="dict.dictValue"
              >{{ $t(dict.dictLabel) }}</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('备注')" prop="remark">
            <el-input v-model="form.remark" type="textarea" :placeholder="$t('备注')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
      </el-row>
      <FileTable :list.sync="form.fileList" data-type="fund_terms" :business-id="autoBusinessId($route.query.id, form)" />
    </el-form>
    <div v-show="!btnHide" slot="footer" class="dialog-footer" style="text-align: center;margin-top: 10px">
      <!--保存，保存并启动流程，取消 三个按钮-->
      <SaveBtn has-permi="fund:terms" :cancel-show="false" />
    </div>
  </div>
</template>

<script>
    import { saveFundTerms, getFundTermsByFundId } from '@/api/fund/terms/fundTerms'
    export default {
        data() {
            return {
                // 产业方向 字典fund_direction_industry字典
                industryDirectionOptions: [], // 政策分类 字典fund_policy_classification字典
                policySortOptions: [], // 表单参数
                form: {
                  industryDirection: [],
                  policySort: [],
                  fileList: []
                },
                // 遮罩层
                loading: false,
                // 表单校验
                rules: {},
                // 是否隐藏保存等按钮
                btnHide: false
            }
        },
        mounted() {
          this.$bus.$emit('async_done')
        },
        created() {
            this.getDicts('fund_direction_industry').then(response => {
                this.industryDirectionOptions = response.data
            })
            this.getDicts('fund_policy_classification').then(response => {
                this.policySortOptions = response.data
            })
        },
        methods: {
            // 初始化数据
            init(data) {
              this.loading = true
              if (data.id !== null && data.id !== undefined) {
                getFundTermsByFundId(data.id).then(response => {
                  if (response.data != null) {
                    this.form = response.data
                  } else {
                    this.reset()
                  }
                  this.loading = false
                })
              } else {
                this.reset()
                this.loading = false
              }
            },
            // 表单重置
            reset() {
                this.form = {
                id: undefined,
                fundId: this.$route.query.id,
                adminRights: undefined,
                adminDuty: undefined,
                investorRights: undefined,
                investorDuty: undefined,
                fundFee: undefined,
                fundBusinessPay: undefined,
                fundCondition: undefined,
                keyPersonClause: undefined,
                investStrategy: undefined,
                keyTransactionTerms: undefined,
                investLimit: undefined,
                otherExplain: undefined,
                targetInvestArea: undefined,
                equityEnsureMode: undefined,
                exitMode: undefined,
                fundTerm: undefined,
                fileList: [],
                otherCondition: undefined,
                generalPartnerDuty: undefined,
                gainClashSolution: undefined,
                infoDisclosure: undefined,
                managerAndManagementFee: undefined,
                incomeDistributionPlan: undefined,
                distributionTimePoint: undefined,
                distributionOrder: undefined,
                nonCashDistribution: undefined,
                industryDirection: [],
                policySort: [],
                remark: undefined,
                createBy: undefined,
                createTime: undefined,
                updateBy: undefined,
                updateTime: undefined,
                delFlag: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                this.$parent.$parent.formOpen = false
                // 刷新list页面
                this.$parent.$parent.getList()
            },
            /** 提交按钮 */
            submitForm: function() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveFundTerms(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                                this.form = response.data
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        }).catch(() => {
                          this.loading = false
                        })
                    } else {
                      this.locationError(document)
                    }
                })
           }

        }

    }
</script>
